from fastapi import Query
from qiniu import Auth

from app.core.BaseResponse import success
from app.service.upload import q_box


async def upload_token(
        bucket: str = Query(...),
):
    bucket_dict = {
        'media': {
            "name": "dome-media",
            "host": "http://media.zc0901.com"
        },
        'static': {
            "name": "dome-static",
            "host": "http://static.zc0901.com"
        },
    }
    info = bucket_dict.get(bucket, {})

    name = info.get('name', '')
    host = info.get('host', '')
    prefix = 'nestciao/'
    bucket_name_1, token = q_box.qiniu_sign(name, prefix=prefix, host=host)
    bucket_name_2, video_token = q_box.qiniu_sign(bucket, prefix=prefix, host=host, is_video=True)
    data = {
        "token": token,
        "videoToken": video_token,
        "info": info,
    }
    return success(data)
